package com.py.credit.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONArray;
import com.py.credit.common.ServiceException;
import com.py.credit.common.logs.ExceptionLogger;
import com.py.credit.common.rest.RestServiceResult;
import com.py.credit.entity.Column;
import com.py.credit.entity.SysUser;
import com.py.credit.entity.common.OptionalColumn;
import com.py.credit.entity.enums.ResourceErrorDataFieldsEnum;
import com.py.credit.service.BatchLogService;
import com.py.credit.service.DataEntryService;
import com.py.credit.service.RemoteBaseService;
import com.py.credit.service.excel.read.service.InspectDataStyleService;
import com.py.credit.utils.ExcelUtil;
import com.py.credit.utils.MapCache;
import com.py.framework.core.annotation.IgnoreAuthority;
import com.py.framework.core.common.Page;
import com.py.framework.core.helper.HttpServletHelper;

@RestController
@RequestMapping(value = "/errorDataProcessing")
public class ErrorDataProcessingController {

	private final static String FRONT_TABLE_ID = "errorDataProcessing";
	@Autowired
	private DataEntryService dataEntryService;

	@Autowired
	private BatchLogService batchLogService;

	@Autowired
	@Qualifier("default")
	private InspectDataStyleService inspectDataStyleService;

	@Autowired
	private RemoteBaseService remoteBaseService;

	/**
	 * 获取初始化列
	 * 
	 * @return
	 */
	@RequestMapping(value = "/getOptionalColums.json")
	public RestServiceResult<List<OptionalColumn>> getOptionalColums() {
		return new RestServiceResult<>(ResourceErrorDataFieldsEnum.getOptionalColumns());
	}

	/**
	 * 手动选择展示列
	 * 
	 * @param columns
	 * @return
	 */
	@RequestMapping(value = "/addShowColunms.json")
	public RestServiceResult<String> addShowColunms(@RequestParam(value = "columns", required = true) String[] columns,
			HttpServletRequest request) {

		RestServiceResult<String> result = new RestServiceResult<>();
		// 获取当前用户信息
		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("ErrorDataProcessingController#addShowColunms", "未获取到当前用户信息！");
				return result;
			}
			String column = StringUtils.join(columns, ",");
			column = column + ",target";
			MapCache.set(userInfo.getId() + "_" + FRONT_TABLE_ID, StringUtils.split(column, ","));
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;
		}
		return new RestServiceResult<String>();
	}

	/**
	 * 获取表头
	 * 
	 * @param tableId
	 * @return
	 */
	@RequestMapping(value = "/getColumnList.json")
	@ResponseBody
	public RestServiceResult<List<Column>> getColumnList(
			@RequestParam(value = "tableId", defaultValue = "", required = true) int tableId) {

		List<Column> clumnList = batchLogService.getColumnList(tableId);
		List<Column> clumnTemp = new ArrayList<>(clumnList.size() + 1);
		Column c = new Column();
		c.setMetricCode("typeMsg");
		c.setMetricName("异常类型");
		c.setFieldType("varchar");
		c.setIsTableShow("Y");
		c.setIsRequire("N");
		c.setIsDetailShow("Y");
		c.setIsPrimary("N");
		c.setIsIndex("N");
		clumnTemp.add(c);
		for (Column column : clumnList) {
			clumnTemp.add(column);
		}
		return new RestServiceResult<List<Column>>(clumnTemp);

	}

	/**
	 * @api {get} /errorDataProcessing/getBatch.json 获取导入数据的表信息列表
	 * @apiName getTableList
	 * @apiVersion 0.0.1
	 * @apiGroup 异常数据管理
	 * 
	 * @apiParam {String} startTime 开始时间(选填)
	 * @apiParam {String} endTime 结束时间 (选填)
	 * @apiParam {String} deptId 部门id (选填)
	 * @apiParam {String} code 库id (必需)
	 * @apiParam {String} tableName 表的中文名 (选填)
	 * @apiParam {String} condition 查询条件(可选)
	 * @apiParam {int} limit 每页展示条数 (必需)
	 * @apiParam {int} page 当前页数 (必需)
	 * 
	 * @apiSuccess {String} code 状态码:1 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {Object[]} data 结果集
	 *
	 * @apiSuccessExample {json} 成功返回结果
	 *                    {"code":0,"msg":null,"count":2,"data":[{"tcount":37,"rcount":22,"scount":15,"id":"EX-10000060873-1-20180426-1371","fcount":0,"target":200249,"tableName":"欠缴电费信息"},{"tcount":10,"rcount":9,"scount":1,"id":"EX-10000060882-1-20180426-2307","fcount":0,"target":200250,"tableName":"欠缴燃气信息"}]}
	 * 
	 */
	@RequestMapping(value = "/getBatch.json")
	@ResponseBody
	public RestServiceResult<List<Map<String, Object>>> getTableList(
			@RequestParam(value = "startTime", defaultValue = "", required = true) String startTime,
			@RequestParam(value = "endTime", defaultValue = "", required = true) String endTime,
			@RequestParam(value = "deptId", defaultValue = "", required = true) String deptId,
			@RequestParam(value = "code", defaultValue = "", required = true) String code,
			@RequestParam(value = "tableName", defaultValue = "", required = true) String tableName,
			@RequestParam(value = "condition", defaultValue = "", required = true) String condition, Page page,
			HttpServletRequest request) {

		RestServiceResult<List<Map<String, Object>>> result = new RestServiceResult<List<Map<String, Object>>>();
		// 获取当前用户信息
		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("ErrorDataProcessingController#getTableList", "未获取到当前用户信息！");
				return result;
			}
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;
		}
		String[] configColumns = (String[]) MapCache.get(userInfo.getId() + "_" + FRONT_TABLE_ID);
		List<String> showColumns = (configColumns == null || configColumns.length == 0)
				? ResourceErrorDataFieldsEnum.getDefaultShowColumnEN() : Arrays.asList(configColumns);
		List<Map<String, Object>> tableList = batchLogService.getErrorDataByConditionForPage(showColumns, null,
				condition, deptId, code, startTime, endTime, tableName, page, userInfo);
		return new RestServiceResult<List<Map<String, Object>>>(page.getTotalCount(), tableList);

	}

	/**
	 * 
	 * @api {get} /errorDataProcessing/exportData.json 异常数据导出
	 * @apiName exportData
	 * @apiVersion 0.0.1
	 * @apiGroup 异常数据管理
	 * @apiParam {date} startTime
	 * @apiParam {date} endTime
	 * @apiParam {int} deptId
	 * @apiParam {string} code
	 * @apiParam {string} tableName
	 * @apiParam {string} condition
	 * @apiParamExample {json} 请求参数示例 {}
	 * @apiSuccess {String} code 状态码:1 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {String} data 结果集
	 * @apiSuccessExample {json} 成功返回结果 {}
	 */
	@RequestMapping(value = "/export")
	public RestServiceResult<List<Map<String, Object>>> exportData(
			@RequestParam(value = "startTime", defaultValue = "", required = true) String startTime,
			@RequestParam(value = "endTime", defaultValue = "", required = true) String endTime,
			@RequestParam(value = "deptId", defaultValue = "", required = true) String deptId,
			@RequestParam(value = "code", defaultValue = "", required = true) String code,
			@RequestParam(value = "tableName", defaultValue = "", required = true) String tableName,
			@RequestParam(value = "condition", defaultValue = "", required = true) String condition, Page page,
			HttpServletResponse response, HttpServletRequest request) {
		page.setLimit(1000);

		RestServiceResult<List<Map<String, Object>>> result = new RestServiceResult<List<Map<String, Object>>>();
		// 获取当前用户信息
		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("ErrorDataProcessingController#exportData", "未获取到当前用户信息！");
				return result;
			}
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;
		}

		String[] configColumns = (String[]) MapCache.get(userInfo.getId() + "_" + FRONT_TABLE_ID);
		List<String> showColumns = (configColumns == null || configColumns.length == 0)
				? ResourceErrorDataFieldsEnum.getDefaultShowColumnEN() : Arrays.asList(configColumns);
		List<Map<String, Object>> tableList = batchLogService.getErrorDataByConditionForPage(showColumns, null,
				condition, deptId, code, startTime, endTime, tableName, page, userInfo);
		try {
			ExcelUtil.downloadExcel(response, tableList, "异常数据信息", "异常数据信息", showColumns,
					ResourceErrorDataFieldsEnum.getOptionalColumns());
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("异常数据信息导出异常，请稍后再试！");
			ExceptionLogger.error("异常数据信息导出异常！", e.getMessage(), e);
			return result;
		}
	}

	/**
	 * @api {get} /errorDataProcessing/getErrorDataListForTableId.json 初始化列表数据
	 * @apiName getTableListForPage
	 * @apiVersion 0.0.1
	 * @apiGroup 异常数据管理
	 * @apiParam {String} startTime 开始时间(选填)
	 * @apiParam {String} endTime 结束时间 (选填)
	 * @apiParam {String} tableId 表的id (必需)
	 * @apiParam {int} limit 每页展示条数 (必需)
	 * @apiParam {int} page 当前页数 (必需)
	 * @apiSuccess {String} code 状态码:1 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {Object[]} data 结果集
	 * @apiSuccessExample {json} 成功返回结果
	 *                    {"code":0,"msg":null,"count":8,"data":[{"errorMess":"","JG_GGSY_QJDF_JE":"10000","address":null,"batch_Id":"EX-10000060873-1-20180427-1457","JG_GGSY_QJDF_TS":"7","tybm":"
	 *                    ","JG_GGSY_QJSF_GXSJ":1524629532000,"JG_GGSY_QJDF_ZT":"已经补交","JG_GGSY_QJDF_GXSJ":"备注","record_id":62,"JG_GGSY_QJDF_QJSJ":1524456732000,"JG_GGSY_QJDF_BJRQ":1524543132000,"JG_GGSY_QJDF_SFDW":"收费单位","A000001":"企业1222","A000002":"TY123456789","creditTime":1524828564000,"A000003":"GS12345678","A000004":"ZZ12345678","JG_GGSY_QJDF_QJSD":1524456732000,"A000005":"SW12345678","A000006":"注册地址","status":"R","md5":"DFD3EF061B6B698DBFB0F428BA304293"}]}
	 * 
	 */
	@ResponseBody
	@RequestMapping(value = "/getErrorDataListForTableId.json")
	public RestServiceResult<List<Map<String, Object>>> getTableListForPage(HttpServletRequest request,
			@RequestParam(value = "tableId", defaultValue = "", required = true) int tableId,
			@RequestParam(value = "deptId", defaultValue = "", required = true) Integer deptId,
			@RequestParam(value = "startTime", defaultValue = "", required = true) String startTime,
			@RequestParam(value = "endTime", defaultValue = "", required = true) String endTime, Page page) {
		RestServiceResult<List<Map<String, Object>>> result = new RestServiceResult<>();
		// 获取当前用户信息
		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(HttpServletHelper.getUserToken(request));
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("ErrorDataProcessingController#getTableListForPage", "未获取到当前用户信息！");
				return result;
			}
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;
		}
		try {
			List<Map<String, Object>> data = dataEntryService.getTableListForPage(tableId, startTime, endTime, page,
					userInfo,deptId);
			result.setCount(page.getTotalCount());
			result.setData(data);
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("异常数据详情问题处理异常，请稍后再试！");
			ExceptionLogger.error("ErrorDataProcessingController#getTableListForPage",
					"异常数据详情问题处理异常！ERROR:" + e.getMessage(), e);
			return result;
		}
	}

	/**
	 * @api {get} /errorDataProcessing/errorDataCheck.json 异常数据校验
	 * @apiName errorDataCheck
	 * @apiVersion 0.0.1
	 * @apiGroup 异常数据管理
	 * 
	 * @apiParam {int} tableId 表id(必需)
	 * @apiParam {String} chackData 校验的数据(必须)
	 * 
	 * @apiSuccess {String} code 状态码:1 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {Object[]} data 结果集
	 *
	 * @apiSuccessExample {json} 成功返回结果
	 *                    {"code":0,"msg":null,"count":0,"data":[{}]}
	 * 
	 */
	@RequestMapping(value = "/errorDataCheck.json")
	@ResponseBody
	public RestServiceResult<Object> errorDataCheck(
			@RequestParam(value = "tableId", defaultValue = "", required = true) int tableId,
			@RequestParam(value = "chackData", defaultValue = "", required = true) String chackData) {
		RestServiceResult<Object> result = new RestServiceResult<Object>();
		@SuppressWarnings("unchecked")
		String replacement = "\\'";
		String checkData = chackData.replace("'", replacement);
		Map<String, Object> data = JSONArray.parseObject(checkData, Map.class);
		 for (Map.Entry<String, Object> entry : data.entrySet()) {
			    if(!((String) entry.getValue()).replace("'" , replacement).equals(entry.getValue())) {
			    entry.setValue(((String) entry.getValue()).replace("'" , replacement));
			    }
			    }
		try {
			List<Column> column = batchLogService.getColumnList(tableId);
			data.put("tableId", tableId);
			// 数据校验
			String sb = inspectDataStyleService.dataCheck(tableId, data, column);
			if (StringUtils.isNotBlank(sb)) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg(sb);
			}
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("异常数据校验异常，请稍后再试！");
			ExceptionLogger.error("ErrorDataProcessingController#errorDataCheck", "异常数据校验异常！ERROR:" + e.getMessage(),
					e);
			return result;
		}
	}

	/**
	 * @api {get} /errorDataProcessing/updataData.json 异常数据修改
	 * @apiName updataData
	 * @apiVersion 0.0.1
	 * @apiGroup 异常数据管理
	 * 
	 * @apiParam {int} tableId 表id(必需)
	 * @apiParam {String} chackData 修改的数据(必须)
	 * @apiParam {int} dataId 数据id(必需)
	 * 
	 * @apiSuccess {String} code 状态码:1 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {Object[]} data 结果集
	 *
	 * @apiSuccessExample {json} 成功返回结果
	 *                    {"code":0,"msg":null,"count":0,"data":[{}]}
	 * 
	 */
	@RequestMapping(value = "/updataData.json")
	@ResponseBody
	public RestServiceResult<Object> updataData(
			@RequestParam(value = "tableId", defaultValue = "", required = true) int tableId,
			@RequestParam(value = "chackData", defaultValue = "", required = true) String chackData,
			@RequestParam(value = "dataId", defaultValue = "", required = true) int dataId) {
		RestServiceResult<Object> result = new RestServiceResult<Object>();
		@SuppressWarnings("unchecked")
		String replacement = "\\'";
		String checkData = chackData.replace("'", replacement);
		Map<String, Object> data = JSONArray.parseObject(checkData, Map.class);
		 for (Map.Entry<String, Object> entry : data.entrySet()) {
			    if(!((String) entry.getValue()).replace("'" , replacement).equals(entry.getValue())) {
			    entry.setValue(((String) entry.getValue()).replace("'" , replacement));
			    }
			    }
		try {
			List<Column> columns = batchLogService.getColumnList(tableId);
			// 数据校验
			String sb = inspectDataStyleService.dataCheck(tableId, data, columns);
			if (StringUtils.isNotBlank(sb)) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg(sb);
				return result;
			}
			dataEntryService.updataData(tableId, data, columns, dataId);
			return result;
		} catch (ServiceException e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg(e.getMessage());
			ExceptionLogger.error("ErrorDataProcessingController#updataData", "ERROR:" + e.getMessage(), e);
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("异常数据保存异常，请稍后再试！");
			ExceptionLogger.error("ErrorDataProcessingController#updataData", "异常数据保存异常！ERROR:" + e.getMessage(), e);
			return result;
		}
	}

	/**
	 * @api {get} /errorDataProcessing/deleteData.json 异常数据删除
	 * @apiName deleteData
	 * @apiVersion 0.0.1
	 * @apiGroup 异常数据管理
	 * 
	 * @apiParam {int} tableId 表id(必需)
	 * @apiParam {int} dataId 数据id(必需)
	 * 
	 * @apiSuccess {String} code 状态码:1 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {Object[]} data 结果集
	 *
	 * @apiSuccessExample {json} 成功返回结果
	 *                    {"code":0,"msg":null,"count":0,"data":[{}]}
	 * 
	 */
	@RequestMapping(value = "/deleteData.json")
	@ResponseBody
	public RestServiceResult<Object> deleteData(
			@RequestParam(value = "tableId", defaultValue = "", required = true) int tableId,
			@RequestParam(value = "dataIds", defaultValue = "", required = true) String dataIds) {
		RestServiceResult<Object> result = new RestServiceResult<>();
		List<String> idList = java.util.Arrays.asList(dataIds.split(","));
		try {
			for(String id:idList) {
				dataEntryService.deleteData(tableId, Integer.valueOf(id));
			}
			
		} catch (ServiceException e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg(e.getMessage());
			ExceptionLogger.error("ErrorDataProcessingController#deleteData", "ERROR:" + e.getMessage(), e);
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("异常数据删除异常，请稍后再试！");
			ExceptionLogger.error("ErrorDataProcessingController#deleteData", "ERROR:" + e.getMessage(), e);
			return result;
		}
		return result;
	}

	/**
	 * @api {get} /errorDataProcessing/selectData.json 异常数据抬头数列展示
	 * @apiName selectData
	 * @apiVersion 0.0.1
	 * @apiGroup 异常数据管理
	 * 
	 * @apiParam {String} startTime 开始时间(选填)
	 * @apiParam {String} endTime 结束时间 (选填)
	 * @apiParam {String} deptId 部门id (必选)
	 * @apiParam {String} code 库 (必选)
	 * @apiParam {String} tableName 表的中文名 (选填)
	 * @apiParam {int} limit 每页展示条数 (必需)
	 * @apiParam {int} page 当前页数 (必需)
	 * 
	 * @apiSuccess {String} code 状态码:1 成功 -1 失败
	 * @apiSuccess {String} msg 错误信息
	 * @apiSuccess {int} count 结果集数据量
	 * @apiSuccess {Object[]} data 结果集
	 *
	 * @apiSuccessExample {json} 成功返回结果
	 *                    {"code":0,"msg":null,"count":0,"data":{"tcount":47,"rcount":31,"scount":16,"fcount":0}}
	 * 
	 */
	@RequestMapping(value = "/selectData.json")
	@ResponseBody
	public RestServiceResult<Map<String, Object>> selectData(
			@RequestParam(value = "startTime", defaultValue = "", required = true) String startTime,
			@RequestParam(value = "endTime", defaultValue = "", required = true) String endTime,
			@RequestParam(value = "deptId", defaultValue = "", required = true) String deptId,
			@RequestParam(value = "code", defaultValue = "", required = true) String code,
			@RequestParam(value = "tableId", defaultValue = "", required = true) String tableId,
			HttpServletRequest request) {

		RestServiceResult<Map<String, Object>> result = new RestServiceResult<Map<String, Object>>();
		String jdToken = HttpServletHelper.getUserToken(request);
		// 获取当前用户信息
		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(jdToken);
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("ErrorDataProcessingController#selectData", "未获取到当前用户信息！");
				return result;
			}
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;
		}
		if (userInfo.getUserType() > 1) {
			userInfo.setId(null);
		}
		Map<String, Object> map = batchLogService.selectData(userInfo, deptId, code, startTime, endTime, tableId);
		try {
			result.setData(map);
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("系统异常，请稍后再试！");
			ExceptionLogger.error("异常数据抬头数列展示异常！", e.getMessage(), e);
			return result;
		}
	}
	
	@RequestMapping(value = "/selectTotal.json")
	@ResponseBody
	public RestServiceResult<Map<String, Object>> selectTotal(
			
			HttpServletRequest request) {

		RestServiceResult<Map<String, Object>> result = new RestServiceResult<Map<String, Object>>();
		String jdToken = HttpServletHelper.getUserToken(request);
		// 获取当前用户信息
		RestServiceResult<SysUser> user = remoteBaseService.getCurrentUser(jdToken);
		SysUser userInfo = null;
		if (RestServiceResult.CODE_SUCCESS == user.getCode()) {
			userInfo = user.getData();
			if (null == userInfo || userInfo.getId() <= 0) {
				result.setCode(RestServiceResult.CODE_UNKNOW);
				result.setMsg("系统异常，请稍后再试！");
				ExceptionLogger.error("ErrorDataProcessingController#selectData", "未获取到当前用户信息！");
				return result;
			}
		} else {
			result.setCode(user.getCode());
			result.setMsg(user.getMsg());
			return result;
		}
		if (userInfo.getUserType() > 1) {
			userInfo.setId(null);
		}
		Map<String, Object> map = batchLogService.selectTotal(userInfo);
		try {
			result.setData(map);
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("系统异常，请稍后再试！");
			ExceptionLogger.error("异常数据抬头数列展示异常！", e.getMessage(), e);
			return result;
		}
	}
	
	@IgnoreAuthority
	@RequestMapping(value = "/selectTotalSCreen.json")
	@ResponseBody
	public RestServiceResult<Map<String, Object>> selectTotalSCreen(
			
			HttpServletRequest request) {

		RestServiceResult<Map<String, Object>> result = new RestServiceResult<Map<String, Object>>();
		SysUser  userInfo = new SysUser();
		userInfo.setRoleName("系统管理员");
		Map<String, Object> map = batchLogService.selectTotal(userInfo);
		try {
			result.setData(map);
			return result;
		} catch (Exception e) {
			result.setCode(RestServiceResult.CODE_UNKNOW);
			result.setMsg("系统异常，请稍后再试！");
			ExceptionLogger.error("异常数据抬头数列展示异常！", e.getMessage(), e);
			return result;
		}
	}
}
